package com.lx.jdbc;

import javax.swing.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/*
*JDBC快速入门
**/
public class JdbcDemo1 {
    public static void main(String[] args) throws Exception {
        //1. 导入驱动jar包
        //2. 注册驱动
        Class.forName("com.mysql.jdbc.Driver");
        //3. 获取数据库连接对象
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "123456");
        //4. 定义sql语句
        String sql = "select * from student1";
        //5. 获取执行sql的对象 Statement
        Statement stmt = conn.createStatement();
        //6. 执行sql语句 executeQuery执行DQL ResultSet封装查询结果  executeUpdate执行DML DDl
        ResultSet resultSet = stmt.executeQuery(sql);
//        String sql2 = "update student1 set name = 'll'";
//        int i = stmt.executeUpdate(sql2);
        //7. 处理结果
        System.out.println(resultSet+"--");
        //8. 释放资源
        stmt.close();
        conn.close();
    }
}
